const KoaRouter = require('koa-router');
const { resSuccess,resError } = require('./common');
const { set, cancel } = require('./src/c/timer');

const router = new KoaRouter();

/**
 * 设置定时器
 */
router.post('/timer/set',async (ctx,next) =>{
    try {
        let param = ctx.request.body;
        let {data,msg} = await set(ctx.request.uuid,param);
        next();
        await resSuccess(ctx,msg,data);
    } catch (error) {
        await resError(ctx,(error.message || error));
    }
});

/**
 * 关闭定时器
 */
 router.post('/timer/cancel',async (ctx,next) =>{
    try {
        let param = ctx.request.body;
        let {data,msg} = await cancel(ctx.request.uuid,param);
        next();
        await resSuccess(ctx,msg,data);
    } catch (error) {
        await resError(ctx,(error.message || error));
    }
});

module.exports = router;
